package cn.dengta.webapp.trade.entity;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;

import cn.dengta.common.util.Formats;
import cn.dengta.webapp.base.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

@Getter
@Setter
@Accessors(chain = true)
@TableName("dt_user_call_statistics")
public class UserCallStatistics extends BaseEntity {

	/** 用户id */
	private Long userId;
	/** 统计日期 */
	private Date addDate;
	/** 主动拨打的音频次数 */
	private Integer audioSend;
	/** 主动拨打音频接通数 */
	private Integer audioSendAccepted;
	/** 主动拨打的视频次数 */
	private Integer videoSend;
	/** 主动拨打视频接通数 */
	private Integer videoSendAccepted;
	/** 接收到的音频次数 */
	private Integer audioGet;
	/** 接收到的音频接通次数 */
	private Integer audioGetAccepted;
	/** 接收到的视频次数 */
	private Integer videoGet;
	/** 接收到的视频接通次数 */
	private Integer videoGetAccepted;
	/** 收入 */
	private BigDecimal integral;
	/** 时长 */
	private Integer duration;
	/** 搭讪新用户 */
	private Integer greetNewUser;
	/** 联系的老用户 */
	private Integer oldUser;
	/** 3天留存 */
	private Integer threeKeep;
	/** 7天留存 */
	private Integer sevenKeep;
	/** 15天留存 */
	private Integer fifteenKeep;

	public static final UserCallStatistics init(Long userId, Date addDate) {
		UserCallStatistics ucs = new UserCallStatistics();
		ucs.setUserId(userId);
		ucs.setAddDate(addDate);
		return ucs;
	}

	public BigDecimal videoSendRate() {
		if (this.videoSend > 0) {
			BigDecimal decimal = BigDecimal.valueOf(this.videoSendAccepted);
			return decimal.divide(BigDecimal.valueOf(this.videoSend), 2, RoundingMode.HALF_UP);
		}
		return BigDecimal.ZERO;
	}

	public BigDecimal videoGetRate() {
		if (this.videoGet > 0) {
			BigDecimal decimal = BigDecimal.valueOf(this.videoGetAccepted);
			return decimal.divide(BigDecimal.valueOf(this.videoGet), 2, RoundingMode.HALF_UP);
		}
		return BigDecimal.ZERO;
	}

	public BigDecimal audioSendRate() {
		if (this.audioSend > 0) {
			BigDecimal decimal = BigDecimal.valueOf(this.audioSendAccepted);
			return decimal.divide(BigDecimal.valueOf(this.audioSend), 2, RoundingMode.HALF_UP);
		}
		return BigDecimal.ZERO;
	}

	public BigDecimal audioGetRate() {
		if (this.audioGet > 0) {
			BigDecimal decimal = BigDecimal.valueOf(this.audioGetAccepted);
			return decimal.divide(BigDecimal.valueOf(this.audioGet), 2, RoundingMode.HALF_UP);
		}
		return BigDecimal.ZERO;
	}

	public String getAddDate_() {
		return Formats.formatDate_D(this.addDate);
	}

	public static final String USER_ID = "user_id";
	public static final String ADD_DATE = "add_date";

}
